<%layout("/common/_layout.html"){ %>
<%#ajax userTable:{%>
<div class="am-cf am-padding">
  <div class="am-fl am-cf"> <strong class="am-text-primary am-text-lg">订单管理</strong>
    /
    <small>充值缴费订单管理</small>
  </div>
</div>
<div class="am-g">

  <div class="am-u-sm-12">
    <form class="am-form" id="list-form" action="${base}/rechargeOrder/list" method="post">
      <input type="hidden" id="keywords" name="keywords" value='${keywords!""}' />
      <input type="hidden" id="isExport" name="isExport" value='${isExport!"0"}' />
      <table class="am-table am-table-bordered am-table-radius table-main am-padding-0">
        <tbody>
         <tr>
            <th class="am-text-middle">所属机构</th>
            <td>
              <div class="am-u-sm-10">
               <select data-am-selected="{btnSize:'sm',maxHeight: 200,btnWidth: '100%',searchBox: 1}" name="org_id" id="org_id">
                            <%for(orgNode in orgList){%>
                            <option value="${orgNode.value}" <%if(org_id==orgNode.value){%>
                                selected
                                <%}%>>${orgNode.key}</option>
                            <%}%></select>
              </div>
            </td>
            
            <th class="am-text-middle">创建时间</th>
            <td>
              <div class="am-u-sm-10">
                <div class="am-form am-form-inline">
                  <div class="am-form-group am-form-icon"> <i class="am-icon-calendar"></i>
                    <input type="text" class="am-form-field am-input-sm" placeholder="开始时间" data-am-datepicker id="start_date" value="${start_date!}" readonly></div>
                  <div class="am-form-group">至</div>
                  <div class="am-form-group am-form-icon"> <i class="am-icon-calendar"></i>
                    <input type="text" class="am-form-field am-input-sm" placeholder="结束时间" data-am-datepicker id="end_date" value="${end_date!}" readonly></div>
                </div>
              </div>
            </td>

            
          </tr>
          
         <tr>
            <th class="am-text-middle">DZG订单号</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="order_id" class="am-form-field am-input-sm" value="${order_id!}" />
              </div>
            </td>
            <th class="am-text-middle">移动订单号</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="cmcc_id" class="am-form-field am-input-sm" value="${cmcc_id!}" />
              </div>
            </td>
          </tr>
          <tr>
            <th class="am-text-middle">充值手机号</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="phone_number" class="am-form-field am-input-sm" value="${phone_number!}" />
              </div>
            </td>
            <th class="am-text-middle">办理人手机号</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="staff_phone" class="am-form-field am-input-sm" value="${staff_phone!}" />
              </div>
            </td>
          </tr> 
          
          <tr>
            <th class="am-text-middle">支付方式</th>
            <td>
              <div class="am-u-sm-10">
                <select data-am-selected="{btnSize:'sm',btnWidth: '100%'}" id="pay_plat" name="pay_plat" >
                  <option value="-1" <%if((!has(pay_plat))||(pay_plat! == "-1")) {%>
                  selected
                  <%}%>>全部</option>

                  <option value="2" <%if(pay_plat! == "2") {%>
                  selected
                  <%}%>>建行/银联</option>
                  <option value="3" <%if(pay_plat! == "3") {%>
                  selected
                  <%}%>>微信</option>
                  <option value="1" <%if(pay_plat! == "1") {%>
                  selected
                  <%}%>>支付宝</option>
                </select>
                </div>
            </td>
            <th class="am-text-middle">支付状态</th>
            <td>
              <div class="am-u-sm-10">
                <select multiple data-am-selected="{btnSize:'sm',btnWidth: '100%'}" id="pay_status" name="pay_status" >
                  <option value="-1" <%if(array.contain(pay_status!,"-1")) {%>
                    selected
                    <%}%>>全部</option>
                  <option value="0" <%if(array.contain(pay_status!,"0")) {%>
                    selected
                    <%}%>>未支付</option>
                  <option value="1" <%if((!has(pay_status))||(array.contain(pay_status!,"1"))) {%>
                    selected
                    <%}%>>已支付</option>
                  <option value="5" <%if(array.contain(pay_status!,"5")) {%>
                    selected
                    <%}%>>已退款</option>
                  <option value="6" <%if(array.contain(pay_status!,"6")) {%>
                    selected
                    <%}%>>退款失败</option>
                </select>
                </div>
            </td>
          </tr> 
          
          <tr>
            
            <th class="am-text-middle">充值结果</th>
            <td>
               <div class="am-u-sm-10">
                <select data-am-selected="{btnSize:'sm',btnWidth: '100%'}" id="order_status" name="order_status" >
                  <option value="-1" <%if(order_status! == "-1") {%>
                    selected
                    <%}%>>全部</option>
                  <option value="1" <%if((!has(order_status))||(order_status! == "1")) {%>
                    selected
                    <%}%>>成功</option>
                  <option value="2" <%if(order_status! == "2") {%>
                    selected
                    <%}%>>失败</option>
                </select>
                </div>
            </td>
            <th class="am-text-middle"></th>
            <td>
              <div class="am-u-sm-10">
             
              </div>
            </td>
            
          </tr>
         
          <tr>
            <td colspan="2">
              <span class="am-text-nowrap am-text-danger am-l">*默认显示当天、成功支付、办理成功的数据；--其他情况请自行选择搜索条件查询.</span>
              <br>
              <span class="am-text-nowrap am-text-danger am-l">此处仅为建行支付订单。</span>
              <!-- <span class="am-text-nowrap am-text-danger am-l">此处仅为建行、银联支付订单。</span> -->
            </td>
            <td colspan="2">
              <div align='right'>
                <button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary" id="submit-btn">搜索</button>
                <%if(so.hasPermission("RECHARGE_ORDER_EXPOR")) {%>
                <button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary" id="export-btn">导出</button>
                <%}%></div>
            </td>
          </tr>
          <tr id='downloadAlertZone' style="display:none">
            <td colspan="4">
              <div id='downloadAlert' class="am-alert am-alert-warning" data-am-alert>
                <p id="downloadAlertMsg">导出失败</p>
              </div>
            </td>
          </tr>
          <tr id="download" style="display:none">
            <td colspan="4">
              <div align='center'>
                <a id="downloadlink" href="#">导出成功，点击下载</a>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </form>
  </div>
  
  <div class="am-u-sm-12 am-u-md-12" style="padding:0 1.6rem 1.6rem 1rem;margin:0;">
    <div class="am-btn-toolbar" style="padding-left:.5rem;"></div>
  </div>
  
</div>

<div class="am-g">
  <div class="am-u-sm-12">
    <div class="am-scrollable-horizontal">
      <table class="am-table am-table-striped am-table-hover table-main">
        <thead>
          <tr class="am-text-nowrap">
            <th class="table-title">DZG订单号</th>
            <th class="table-title">移动订单号</th>
            <th class="table-title">充值手机号</th>
            <th class="table-title">充值金额(元)</th>
            <th class="table-title">支付金额(元)</th>
            <th class="table-title">支付方式</th>
            <th class="table-title">支付状态</th>
            <th class="table-title">支付时间</th>
            <th class="table-title">办理人</th>
            <th class="table-title">办理人手机号</th>
            <th class="table-title">办理人工号</th>
            <th class="table-title">地市</th>
            <th class="table-title">区县</th>
            <th class="table-title">网点编码</th>
            <th class="table-title">网点名称</th>
            <th class="table-title">网点类型</th>
            <th class="table-title">创建时间</th>
            <th class="table-title">充值结果</th>
            <%if(so.hasPermission("RECHARGE_ORDER_REFUN")) {%> 
            <th class="table-title">操作</th>
             <%}%>
            <%if(so.hasPermission("RECHARGE_ORDER_DESC")) {%>
            <th class="table-title">结果说明</th>
             <%}%>
            <th class="table-title">退款说明</th>
            <th class="table-title">退款时间</th>
            <th class="table-title">充值说明</th>
            <th class="table-title">充值时间</th>
          </tr>
        </thead>
        <tbody>
          <%for(list in pager.list!){%>
          <tr>
            <td>${list.order_id}</td>
            <td>${list.cmcc_id}</td>
            <td>${list.recharge_phone}</td>
            <td>${list.recharge_money}</td>
            <td>${list.pay_amount}</td>
            <td>${list.pay_method}</td>       
            <td>${list.pay_state}</td>
            <td class="am-text-nowrap">${list.pay_datetime}</td>
            <td>${list.staff_name}</td>
            <td>${list.staff_phone}</td>
            <td>${list.emp_code}</td>
            <td>${list.city}</td>
            <td>${list.area}</td>
            <td>${list.NumCode}</td>
            <td>${list.DisplayName}</td>
            <td>${list.sitetype}</td>
            <td class="am-text-nowrap">${list.created_datetime}</td>
            <td>${list.order_state}</td>
            
            <%if(so.hasPermission("RECHARGE_ORDER_REFUN")) {%> 
            
            <td>
            
             <%if (list.can_refund=='1'){%>
            <div class="am-btn-toolbar">
                  <div class="am-btn-group am-btn-group-xs">   
                    <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary"
                            onclick="queryRechargeStatus('${list.order_id}','${list.recharge_phone}',
                            '${list.pay_datetime}','${list.emp_code}','${list.pay_amount}','${base}');">退款</button>
                  </div>
            </div>
            <%}%>  
             
            </td>
             <%}%>
            
            <%if(so.hasPermission("RECHARGE_ORDER_DESC")) {%>
            <td>${list.operated_desc}</td>
            <%}%>
            <td>${list.refund_desc}</td>
            <td class="am-text-nowrap">${list.refund_datetime}</td>
            <td>${list.recharge_desc}</td>
            <td class="am-text-nowrap">${list.recharge_datetime}</td>
          </tr>
          <%}%></tbody>
      </table>
    </div>
    <div class="am-cf">
      <!-- 分页 -->
      <%if (pager.list.~size >
      0){%>
      <div class="am-fr">
        <% include("/admin/common_pager.tpl"){}%></div>
      <%}else{%>
      <div class="am-kai">
        <h3>没有找到任何记录!</h3>
      </div>
      <%}%></div>

  </div>
</div>
<script type="text/javascript" src="${base}/template/admin/js/ccb.js?v=2"></script>
<script type="text/javascript">
    $(function(){
      var keywordsObj = {};
      var canSubmit = true;
      function setKeyWords(){
            if($("#order_id").val())
              keywordsObj.order_id = $("#order_id").val();
            if($("#cmcc_id").val())
              keywordsObj.cmcc_id = $("#cmcc_id").val();
            if($("#phone_number").val())
              keywordsObj.phone_number = $("#phone_number").val();
            if($("#staff_phone").val())
              keywordsObj.staff_phone = $("#staff_phone").val();
            if($("#pay_status").val()){
              var curStatus = $("#pay_status").val();
              if(curStatus.length > 1 && curStatus[0] == "-1"){
                alert("请单独查询支付状态为'全部'的订单！");
                canSubmit = false;
              }else{
                keywordsObj.pay_status = $("#pay_status").val();
                canSubmit = true;
              }
            }else{
              alert("请选择支付状态！");
              canSubmit = false;
            }
              
            if($("#pay_plat").val())
              keywordsObj.pay_plat = $("#pay_plat").val();
              
            if($("#start_date").val())
              keywordsObj.start_date = $("#start_date").val();
            if($("#end_date").val())
              keywordsObj.end_date = $("#end_date").val();
              
            if($("#order_status").val())
             keywordsObj.order_status = $("#order_status").val();
             
            if($("#org_id").val()){
              keywordsObj.org_id = $("#org_id").val();
             }

            var keywords = "";
            if(!$.isEmptyObject(keywordsObj)){
              keywords = JSON.stringify(keywordsObj);
            }
            console.log("keywords = "+ keywords);

            $("#keywords").val(keywords);
      }
      
      $("#submit-btn").on("click",function(){
        setKeyWords();
        if(canSubmit){
          console.log("canSubmit = "+canSubmit);
          console.log(JSON.stringify(setKeyWords()));
          $("#isExport").val("0");
          $("#list-form").submit();
        }
      });
      $('#downloadAlert').on('closed.alert.amui', function() {
        $('#downloadAlertZone').hide();
      });

      $("#export-btn").on("click",function(){
        setKeyWords();
        if(canSubmit){
            console.log("canSubmit = "+canSubmit);
            $('#download').hide();
            $('#downloadAlertZone').hide();
            //loading层
            var index = parent.layer.load(0, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $("#isExport").val("1");
            //$("#list-form").submit();
            var formParam = $("#list-form").serialize();//序列化表格内容为字符串
            console.log('formParam='+formParam);
            $.ajax({
              type:'post',
              url:'${base}/rechargeOrder/list',
              data:formParam,
              success:function(data){
                console.log(data);
                if(data.status==1){
                   $('#downloadlink').text(data.message);
                   $('#downloadlink').attr('href',data.url);
                   $('#download').show();
                }else{
                   $('#downloadAlertMsg').text(data.message);
                   $('#downloadAlertZone').show();
                }
                parent.layer.close(index);
              },
              error: function() {
                 parent.layer.close(index);
              }
            });
          }
        });
    });
  </script>
<%}%>
<%}%>